
/**
 * 修改支付密码 执行
 * @param newPayPsw    用户输入的新支付密码
 */
function ajaxUpdatePayPsw() {
    //loading("数据提交中...")
    var newPayPsw = $("#newPassword").val();
    var url = "/Lvscore_User_M/account/ajaxUpdatePayPsw";
    $.ajax({
        url:url,
        data:{'newPayPsw': newPayPsw},
        type:"post",
        success:function (data) {
            //$(".loadingBox").hide();
            if (data == 1) {
                window.location.href = "/Lvscore_User_M/userWeb/views/accounterCenter/changePaymentPsdSucc.html"
            } else if(data==-1){
                validateSpanMsg("newPsd1", '新密码与旧密码不能相同');
            }else if(data==-2){
                validateSpanMsg("newPsd1", '支付密码不能和登录密码相同');
            }
        },
        //error:function(){
        //    //$(".loadingBox").hide();
        //    alertBox("网络异常，请重试");
        //},
        dataType:"json"
    });
}

$(function () {
    $(".oldPassword").val("");
    $(".newPassword").val("");
    $(".sure").val("");
    //实时监控输入框
    inputChange(".oldPassword","#oldPsd");
    inputChange(".newPassword","#newPsd1");
    inputChange(".sure","#newPsd2");
    inputChange(".newPassword","#defrentError");
    inputChange(".sure","#defrentError");
    function oldPsdMessage(){
        var oldPsd = $(".oldPassword").val();
        if (oldPsd == null || oldPsd == "") {
            validateSpanMsg("oldPsd","请输入旧密码");
            return false;
        }else if(!(isPassword(oldPsd))){
            validateSpanMsg("oldPsd","旧密码错误");
            return false;
        }else{
            return true;
        }
    }
    function newPsdMessage1(){
        var newPsd = $(".newPassword").val();
        var user = getUser_C();
        if (newPsd == null || newPsd == "") {
            validateSpanMsg("newPsd1","请输入新密码");
            return false;
        }else if(!(isPassword(newPsd))){
            validateSpanMsg("newPsd1","密码格式不正确");
            return false;
        }else{
            return true;
        }
    }
    function newPsdMessage2(){
        var confPsd = $(".sure").val();
        var newPsd = $(".newPassword").val();
        if (confPsd == null || confPsd == "") {
            validateSpanMsg("newPsd2","请确认新密码");
            return false;
        }else if(newPsd != confPsd){
            validateSpanMsg("defrentError","两次输入的密码不一致");
            return false;
        }else{
            return true;
        }
    }
    $(".oldPassword").blur(function(){
        oldPsdMessage();
    })
    $(".newPassword").blur(function(){
        newPsdMessage1();
    })
    $(".sure").blur(function(){
        newPsdMessage2();
    })
    getUrl('accounterCenter/accounterSecurity');
    $(".sub").click(function () {
        //var user = getUser_C();
        //console.dir(user);
        var oldPsd = $("#oldPassword").val();
        var newPsd = $("#newPassword").val();
        var confPsd = $(".sure").val();
        if (oldPsd == null || oldPsd == "") {
            validateSpanMsg("oldPsd","请输入旧密码");
        } else if (newPsd == null || newPsd == "") {
            validateSpanMsg("newPsd1","请输入新密码");
        } else if (!isPassword(newPsd)) {
            validateSpanMsg("newPsd1","密码格式不正确");
        } else if (confPsd == null || confPsd == "") {
            validateSpanMsg("newPsd2","请确认新密码");
        } else if (newPsd != confPsd) {
            validateSpanMsg("defrentError","两次输入的密码不一致");
        } else {
            if (isPassword(newPsd))
                /**
                 * 验证输入的支付密码是否正确
                 */
                ajaxValidateOldPayPsw(oldPsd, ajaxUpdatePayPsw);
        }
    })
});